package com.fuzhixuan.cloud.controller;

import com.fuzhixuan.cloud.entities.CommonResult;
import com.fuzhixuan.cloud.entities.Payment;
import com.fuzhixuan.cloud.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

@RestController
public class Payment8004Controller {
    @Value("${server.port}")
    private Integer port;

    @Autowired
    private PaymentService paymentService;

    @GetMapping(value = "/getServerPort")
    public String getServerPort() {
        return "server consul port: " + port + ":" + UUID.randomUUID();
    }

    @PostMapping(value = "/payment/getById")
    public CommonResult getById(@RequestParam Integer id) {
        Payment payment = paymentService.getPaymentById(id);
        if (payment == null) {
            return CommonResult.fail(444, "查不到数据：" + id);
        }
        return CommonResult.ok(200, payment);
    }

    @GetMapping(value = "/payment/feign/timeout")
    public Integer timeout() {
        try {
            Thread.sleep(3000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return port;
    }
}
